package com.yunduo.service.impl;

import com.yunduo.entity.Good;
import com.yunduo.entity.Order;
import com.yunduo.mapper.GoodMapper;
import com.yunduo.service.GoodService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ChengXin
 * @since 2023-07-12
 */
@Service
public class GoodServiceImpl extends ServiceImpl<GoodMapper, Good> implements GoodService {

    @Resource
    private GoodMapper goodMapper;

    @Override
    public List<Good> selectGoodByTypeId(List<String> ids) {
        return goodMapper.selectGoodByTypeId(ids);
    }

    @Override
    public List<Good> seletGoodByIdsOrderPop(List<String> ids, int count) {
        return goodMapper.seletGoodByIdsOrderPop(ids,count);
    }

    @Override
    public List<Good> seletGoodByOrderPop(int count) {
        return goodMapper.seletGoodByOrderPop(count);
    }

    @Override
    public List<Good> selectGoodsForN(int begin, int end) {
        return goodMapper.selectGoodsForN(begin,end);
    }

    @Override
    public List<Good> selectGoodsForOrderQuery(String name,boolean orderPirce, boolean orderCreate, int page, int item) {
        //计算分页条数
        int currentPageCount = (page-1)*item;
        return goodMapper.selectGoodsForOrderQuery(name,orderPirce,orderCreate,currentPageCount,item);
    }


    /**
     * @param GoodInfo
     * @return map<Good,个数>
     */
    @Override
    public Map<Good,String> getOrdersByOrderInfo(String goodInfo) {
        HashMap<Good, String> goodData = new HashMap<>();
        String[] goods = goodInfo.split(",");
        for (int i = 0; i < goods.length; i++) {
            String[] good = goods[i].split("\\*");
            Good item = this.getById(good[0]);
            goodData.put(item,good[1]);
        }
        return goodData;
    }
}
